-
-
Notifications
You must be signed in to change notification settings - Fork 359
euler.m #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
euler.m #158
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to the team @vasilisk075, thank you for submitting code :)
% Loop over time | ||
while succes==0 | ||
|
||
t(i+1) = t(i) + dt; % Calculate next time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dynamically growing vector sizes is bad practice, they should always be predefined. For t
is is very easy to do since you already know the bounds and the time difference.
y(i+1) = y(i) + f( y(i) )*dt; % Update solution | ||
|
||
% Calculate differce between 2 time steps | ||
error=abs(( y(i+1) - y(i) )/dt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't call this error
, it's not an error, it's a slope. I also wouldn't use that as an indication that the computation is over. I would simply predefine the time vector, calculate the function for all time steps and plot that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your idea but ODEs usually reach a SteadyState, and this particular surely does, so why waste time computing something that practically stays the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if your function was actually a sinusoidal function? It would stop at the first extremum. In general you don't have prior knowledge of the function, and computational time is dirt cheap nowadays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is dirt cheap, if you talk about small problems like that! Generally when i run a big simulation based on some differential equation, i need a creteria indicating that Steady State is reached and thus terminating the simulation. Normaly a don't know the amount of time steps needed for that.
But either way, i think that it is a long discussion, so i am going to update the code according to your suggestions.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yeah, real world is more complex of course. Let's keep it simple here :)
Also if you want your code to be included in the website, you should include the code in the chapter |
I'll do the EditorConfig once this is merged. |
#166 adds Matlab to book.json. Let's just merge that one first and we don't have to deal with it here. |
Implementation of Forward Euler method on Matlab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very clean! Thank you for updating your code.
Matlab implementation of the Forward_Euler method